﻿using System;
using System.Collections.Generic;
using System.Text;
using Watchdog.Bll.Factory;

namespace Watchdog.Bll.Base {

    public partial class TestBase {

        #region [ Local variables ]
        Facade.Test intdata;
        #endregion

        #region [ Constructor(s) ]
        internal TestBase () {
            intdata = new Watchdog.Facade.Test ();
        }
        internal TestBase (Facade.Test test) : base () {
            intdata = test;
        }
        #endregion

        #region [ Field Properties ]
        public int Id {
            get { return intdata.Id; }
        }
        public virtual string Name {
            get { return intdata.Name; }
            set { intdata.Name = value; }
        }
        public virtual int Definition {
            get { return intdata.Definition; }
            set { intdata.Definition = value; }
        }
        public virtual int Zone {
            get { return intdata.Zone; }
            set { intdata.Zone = value; }
        }
        public virtual int TimeOut {
            get { return intdata.TimeOut; }
            set { intdata.TimeOut = value; }
        }
        public virtual bool LogHistory {
            get { return intdata.LogHistory; }
            set { intdata.LogHistory = value; }
        }
        public virtual int State {
            get { return intdata.State; }
            set { intdata.State = value; }
        }
        public virtual DateTime SnoozeUntil {
            get { return intdata.SnoozeUntil; }
            set { intdata.SnoozeUntil = value; }
        }
		#endregion
		
        #region [ Data Methods ]
        public void Update () {
            if (Id == -1)
                TestFactory.Insert ( this );
            else
                TestFactory.Update ( this );
        }

        public void Delete () {
            TestFactory.Delete ( this );
        }
        #endregion

		#region [ Many to many relations native type ]

        //List<int> devices;
        //public List<int> Devices {
        //    get {
        //        // To implement manually
        //        //if ( devices == null )
        //        //	devices = TestFactory.GetByTest(this.Id);
        //        //return devices;
        //    }
        //}

		#endregion

		#region [ Add & Remove methods for many to many relations native type ]

        //public void AddDevice (int device) {
        //    TestFactory.AddDevice (this, device);
        //    //reset the collection;
        //    devices = null;
        //}
		
        //public void RemoveDevice (int device) {
        //    TestFactory.RemoveDevice (this, device);
        //    //reset the collection;
        //    devices = null;
        //}

		#endregion
		
        internal Facade.Test IntData {
            get { return intdata; }
            set { intdata = value; }
        }

        #region [ Equality ]
        public override int GetHashCode () {
            return Id;
        }
        public static bool operator == ( TestBase lt1, TestBase lt2 ) {
            if (System.Object.ReferenceEquals ( lt1, lt2 ))
                return true;

            if ((object)lt1 == null || (object)lt2 == null)
                return false;
            return lt1.Equals ( lt2 );
        }
        public static bool operator != ( TestBase lt1, TestBase lt2 ) {
            if (lt1 == null || lt2 == null)
                return false;
            return !(lt1 == lt2);
        }

        public override bool Equals ( object obj ) {
            if (!(obj is TestBase))
                return false;
            return (this.CompareTo ( obj ) == 0);
        }

        private int CompareTo ( object obj ) {
            if (!(obj is TestBase)) {
                throw new ArgumentException ( "A 'TestBase' object is required for comparison." );
            }
            return this.Id.CompareTo ( ((TestBase)obj).Id );
        }
        #endregion

	}
}
